package com.hfb.mashibing.alip8.mq.rabbit.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtil {

    public static Connection getConnection() throws IOException, TimeoutException {
        // 1、创建连接工厂（设置rabbitMQ的参数）
        // 主机：默认localhost
        // 端口：默认5672
        // 虚拟主机：默认 /
        // 用户名/密码 默认
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("rabbitmq.dev.baiwang-inner.com");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        // 2、创建连接
        Connection connection = connectionFactory.newConnection();

        System.err.println("连接状态"+connection.getServerProperties());

        return connection;
    }
}
